﻿<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Default Examples</title>
		<style>
			form {
				margin: 0;
			}
			textarea {
				display: block;
			}
		</style>
		<link rel="stylesheet" href="../themes/default/default.css" />
		<script type="text/javascript" src="jquery.js"></script>
		<script charset="utf-8" src="../kindeditor-all.js?d=1"></script>
		<script charset="utf-8" src="../lang/zh_CN.js"></script>
		<script>
			var editor = null;
			function fileSave(){
				$.ajax({
					cache:false,
					url:'http://localhost:2016/manager/Dev.do'+window.location.href.substring(window.location.href.indexOf("?")),
					type:'POST',
					data:[{name:'type',value:'savefile'},{name:'EditorValue',value:editor.html()}],
					success:function(data){
						alert(data);
					},
					error:function(err){
						alert(err);
					}
				});
			}
			
			function getSelectedFiles(type){
				$.ajax({
					cache:false,
					url:'http://localhost:2016/manager/Dev.do?type=getSelectedFiles',
					type:'GET',
					data:[],
					success:function(data){
						if(type=='link'){
							var links = data.split(',');
							for(var i=0;i<links.length;i++){
								if(links[i]){
									editor.insertHtml('<a href="http://localhost:2016/manager/Dev.do?type=openfile&pagepath='+links[i]+'" target="eclick_non">'+links[i]+'</a>&nbsp;<br/>');
								}
							}
						}
						if(type=='searchfile'){
							var links = data.split(',');
							for(var i=0;i<links.length;i++){
								if(links[i]){
									editor.insertHtml('<a href="http://localhost:2016/manager/Dev.do?type=searchfile&scope='+links[i]+'&string=*" target="eclick_non">'+links[i]+'</a>&nbsp;<br/>');
								}
							}
						}
					},
					error:function(err){
						alert(err);
					}
				});
			}
			
			// 根据添加的BookMark创建文件链接
			function getBookMarkLinks(){
				$.ajax({
					cache:false,
					url:'http://localhost:2016/manager/Dev.do?type=getBookMarkLinks',
					type:'GET',
					data:[],
					success:function(data){
						$("#getBookMarkLinksId").hide();
						$("#clearBookMarkLinksId").show();
						// alert(data);
						var links = jQuery.parseJSON(data);
						if(data && links.length==0){
							alert(" 检测到你没有在任何文件中添加任何BOOKMARK书签！");
							return;
						}
						for(var i=0;i<links.length;i++){
							if(links[i].msg.length<=1){
								links[i].msg = links[i].path;
							}
							editor.insertHtml('<a href="http://localhost:2016/manager/Dev.do?type=openfile&pagepath='+links[i].path+'&row='+links[i].row+'" target="eclick_non">'+links[i].msg+'</a>&nbsp;<br/>');
						}
					},
					error:function(err){
						alert(err);
					}
				});
			}
			
			// 清空BOOKMARKLINKS的缓存
			function clearBookMarkLinks(){
				$.ajax({
					cache:false,
					url:'http://localhost:2016/manager/Dev.do?type=clearBookMarkLinks',
					type:'GET',
					data:[],
					success:function(data){
						$("#clearBookMarkLinksId").hide();
						$("#getBookMarkLinksId").show();
					},
					error:function(err){
						alert(err);
					}
				});
			}
			
			function addOpenFileDefault(){
				editor.insertHtml('<a href="http://localhost:2016/manager/Dev.do?type=openfile&pagepath=xxxxxx&row=1" target="eclick_non">xxxxxx</a>');
			}
			
			function addSearchFileDefault(){
				editor.insertHtml('<a href="http://localhost:2016/manager/Dev.do?type=searchfile&scope=&string=xxxxxx&row=1" target="eclick_non">xxxxxx</a>');
			}
			
			// 
			function cutScreen(){
				$.ajax({
					cache:false,
					url:'http://localhost:2016/manager/Dev.do?type=cutScreen',
					type:'GET',
					data:[],
					success:function(data){
						if(data){
							editor.insertHtml('<img style="border:1px solid #CCCCCC" src="http://localhost:2016/manager/clientdata/'+ data +'">');
						}
					},
					error:function(err){
						alert(err);
					}
				});
				
			}
			
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					allowFileManager : true
				});
				$('#readone').click();
				$.ajax({
					cache:false,
					url:'http://localhost:2016/manager/Dev.do'+window.location.href.substring(window.location.href.indexOf("?")),
					type:'GET',
					dataType:'text',
					success:function(data){
						editor.html(data);
					},
					error:function(err){
						alert(err.message);
					}
				});
				
				K('input[name=getHtml]').click(function(e) {
					
					// $.post("http://localhost:2017/",{'sss':'sssss'},function(sfd,status,xhr){});
				});
				K('input[name=isEmpty]').click(function(e) {
					alert(editor.isEmpty());
				});
				K('input[name=getText]').click(function(e) {
					alert(editor.text());
				});
				K('input[name=selectedHtml]').click(function(e) {
					alert(editor.selectedHtml());
				});
				K('input[name=setHtml]').click(function(e) {
					editor.html('<h3>Hello KindEditor</h3>');
				});
				K('input[name=setText]').click(function(e) {
					editor.text('<h3>Hello KindEditor</h3>');
				});
				K('input[name=insertHtml]').click(function(e) {
					editor.insertHtml('<strong>插入HTML</strong>');
				});
				K('input[name=appendHtml]').click(function(e) {
					editor.appendHtml('<strong>添加HTML</strong>');
				});
				K('input[name=clear]').click(function(e) {
					editor.html('');
				});
			});
			
			var xmlhttp = null;
			$(function(){
				if (window.XMLHttpRequest)
				  {// code for IE7+, Firefox, Chrome, Opera, Safari
				  xmlhttp=new XMLHttpRequest();
				  }
				else
				  {// code for IE6, IE5
				  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				  }
				xmlhttp.onreadystatechange=function()
				  {
				  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				    {
				    document.getElementById('p1').innerHTML="Last modified: " + xmlhttp.getResponseHeader('Last-Modified');
				    }
				  }
			});
			
			// 设置超链接内嵌TAB页方式打开文件或外部打开文件
			function setMode(){
				
			}
		</script>
	</head>
	<body>
		<div style="width:100%;">
			<input type="button" onclick="fileSave()" value="保存"></input>
			<input id="readone" type="button"  onclick="editor.readonly();this.disabled=true;editone.disabled=false;this.value='当前只读';editone.value='编辑';" value="只读"></input>
			<input id="editone" type="button"  onclick="editor.readonly(false);this.disabled=true;readone.disabled=false;this.value='当前编辑';readone.value='只读';" value="编辑"></input>
			<input type="button" name="button" onclick="getSelectedFiles('link');" value="获取文件链接"></input>
			<input type="button" name="button" onclick="getSelectedFiles('searchfile');" value="获取搜索链接"></input>
			<input type="button" onclick="addOpenFileDefault()" value="文件链接" />
			<input type="button" onclick="addSearchFileDefault()" value="搜索链接" />
			<input type="button" onclick="cutScreen()" value="截图" />
			<input type="button" id="clearBookMarkLinksId" onclick="clearBookMarkLinks()" value="开始获取BOOKMARK" />
			<input type="button" style="display:none;" id="getBookMarkLinksId" onclick="getBookMarkLinks()" value="结束&获取BOOKMARK" />
			<button onclick='window.showModelessDialog(window.location.href,window.location.href,"dialogWidth="+screen.width*0.6+"px;dialogHeight="+screen.height*0.55+"px;resizable=yes")' style="margin-left:5px;">弹出</button>
			<button onclick='window.showModelessDialog("http://git.oschina.net/wanghr/eclick/attach_files","官网","dialogWidth="+screen.width*0.8+"px;dialogHeight="+screen.height*0.75+"px;resizable=yes")' style="margin-left:5px;">官网最新</button>
			<a href="javascript:void(0);" onclick='window.showModelessDialog("http://localhost:2016/manager/api.html","官网","dialogWidth="+screen.width*0.6+"px;dialogHeight="+screen.height*0.55+"px;resizable=yes")' style="margin-right:5px;">API</a>
		</div>
		<textarea name="content" style="width:90%;height:800px;visibility:hidden;">KindEditor</textarea>
		<iframe style='display:none;height:0px;width:0px;' name='eclick_non' ></iframe>
		<p style="display:none;">
			<input type="button" name="getHtml" value="取得HTML" />
			<input type="button" name="isEmpty" value="判断是否为空" />
			<input type="button" name="getText" value="取得文本(包含img,embed)" />
			<input type="button" name="selectedHtml" value="取得选中HTML" />
			<br />
			<br />
			<input type="button" name="setHtml" value="设置HTML" />
			<input type="button" name="setText" value="设置文本" />
			
			<input type="button" name="appendHtml" value="添加HTML" />
			<input type="button" name="clear" value="清空内容" />
			<input type="reset" name="reset" value="Reset" />
		</p>
	</body>
</html>
